package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-31
 * Time: 16:15
 */
public class AddOperation implements IOperations{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加图书");
        if(bookList.usedSize == bookList.books.length) {
            System.out.println("书架空间不足，添加失败");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要添加的图书的名字：");
        String name = scanner.nextLine();
        System.out.println("请输入你要添加的图书的作者：");
        String author = scanner.nextLine();
        System.out.println("请输入你要添加的图书的价格：");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入你要添加的图书的类型：");
        String type = scanner.nextLine();

        Book newBook = new Book(name,author,price,type);
        bookList.books[bookList.usedSize] = newBook;
        bookList.usedSize++;
        System.out.println("添加成功");
    }
}
